// 引入Service和请求头ServiceName
import { Service, ServiceName } from '@/network/http.js'
import axios from 'axios'
import config from '@/network/config.js'
const publicapi = {
  /**
    * 获取字典数据
    */
  getDictData(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listalldict?dicttype=${params}`
    )
  },
  /**
    * 获取省份
    */
  reqGetProvinceData() {
    return Service.get(
      `/${ServiceName}/api/external/publics/getprovince`
    )
  },
  /**
    * 获取城市
    * @param {*} params 根据省份
    */
  reqGetCityData(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/getcitybyprovince?dm=${params}`
    )
  },
  /**
   * 获取权限按钮
   */
  getPermissionsBtn(params) {
    return Service.get(
      `/${ServiceName}/api/external/sysmenubtn/listresourcebtnbyid?menuId=${params}`, { timeout: 30000 }
    )
  },
  /**
   * 文件上传
   */
  getFileInfo(params) {
    return Service.post(
      `/${ServiceName}/api/external/publics/file/upload`, params
    )
  },
  /**
   * 文件下载
   */
  down(id) {
    return axios({
      method: 'get',
      url: `${config.ConfigBaseURL}/wfpms-master-service/api/external/publics/file/down?id=${id}`,
      responseType: 'arraybuffer',
      params: {
        token: window.sessionStorage.getItem('token')
      }
    })
  },
  /**
   * 作业公司查询
   */
  getCompanyList() {
    return Service.get(
      `/${ServiceName}/api/external/publics/listsecondcomp`
    )
  },
  /**
   * 获取货种列表根据货种名称
   * @params cargoCategory:货种名称
   */
  getlistCargoCategory(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listCargoCategory`, { params }
    )
  },
  /**
   * 根据货种获取货名信息
   * @params cargoCategoryCode:货种code
   */
  getListCargo(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listCargo`, { params }
    )
  },
  /**
   * 获取货名信息 -- 远程搜索货名/速记码
   * @params cargo: 货名/速记码
   */
  listCargoByNameCode(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listCargoByNameCode`, { params }
    )
  },
  getDeptList() {
    return Service.get(
      `/${ServiceName}/api/external/publics/listsecondDept`
    )
  },
  /**
   * 获取操作过程/作业过程列表
   * @params mainType: 1 主过程/
   */
  getlistProcess(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listProcess`, { params }
    )
  },
  /**
   * 获取费目列表
   */
  getlistRateItem() {
    return Service.get(
      `/${ServiceName}/api/external/publics/listRateItem`
    )
  },
  /**
   * 获取货主、货代、船代、开证公司
   */
  getlistCustomer(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listCustomer`, { params }
    )
  },
  /**
   * 获取业务单元 - 二次获取直接从本地取
   */
  getListComp() {
    /*const companyList = JSON.parse(sessionStorage.getItem('companyList'))
    if (companyList) {
      return Promise.resolve({ data: { data: companyList } })
    }
    Service.get(
      `/${ServiceName}/api/external/publics/listComp`
    ).then(res => {
      sessionStorage.setItem('companyList', JSON.stringify(res.data.data))
      return Promise.resolve({ data: { data: JSON.parse(sessionStorage.getItem('companyList')) } })
    })*/
    return Service.get(
        `/${ServiceName}/api/external/publics/listComp`
    )
  },

  /**
   * 获取船名航次信息
   */
  getListShipvoyage(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listShipvoyage`, { params }
    )
  },
  /**
   * 根据id 获取 航次信息
   */
  getShipVoyageById(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/getshipvoyagebyid`, { params }
    )
  },
  /**
   * 获取泊位信息 type:Y：主泊位 N:非主泊位 "":全部
   */
  queryberthbytype(type) {
    return Service.get(
      `/${ServiceName}/api/external/publics/queryberthbytype?type=${type}`
    )
  },
  /**
   * 根据泊位id berthId 获取缆桩信息
   */
  queryBittByBerthId(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/queryBittByBerthId`, { params }
    )
  },
  /**
   * 根据停工类型获取停工原因  stopTypeCode
   */
  queryStopReasonByType(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/queryStopReasonByType`, { params }
    )
  },
  /**
   * 获取船名列表
   */
  getshiplist(type) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listshipbyname?type=${type}`
    )
  },
  /**
   * 获取港口列表
   * @params isDomestic:Y是/N否，不传查全部
   */
  getPortList(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listPort`, { params }
    )
  },
  /**
   * 获取港口列表
   * @params assistType:1船舶预报2木材/集装箱卸船3木材发货 海轮预报传1
   */
  getProcessList(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/queryProcessByAssistType`, { params }
    )
  },
  // 查询库号
  querystorehousename() {
    return Service.get(
      `/${ServiceName}/api/external/product/querystorehousename`
    )
  },
  // 查询设备类型
  getEquipmentType() {
    return Service.get(
      `/${ServiceName}/api/external/mtequipment/getEquipmentType`
    )
  },
  /**
   * 查询场地相关信息
   * 参数storageType: 1场地 2库 3车间 4熏蒸库 不传参查全部
   */
  queryStorehouseNameByType(params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/queryStorehouseNameByType?storageType=${params}`
    )
  },
  /**
     * 根据主作业Id查询子作业
     */
  getProcessZiDataById(id) {
    return Service.get(
      `/${ServiceName}/api/external/publics/listProcessZi?process=${id}`
    )
  },
  /**
    * 查询协力队
    */
  getCooperationDataById() {
    return Service.get(
      `/${ServiceName}/api/external/publics/queryoperativeteam`
    )
  },
  /**
   * 查询堆场
   */
  getYardData() {
    return Service.get(
      `/${ServiceName}/api/external/publics/listRateItemYard`
    )
  },
  /**
   * 根据库场id查询货位
   */
  getStorehouseLocation(id) {
    return Service.get(
      `/${ServiceName}/api/external/publics/querybyidHuo?id=${id}`
    )
  },
  /**
   * 查询库场
   */
  listStorehouse () {
    return Service.get(
      `/${ServiceName}/api/external/publics/listStorehouse`
    )
  },
  // 查询作业工段
  getworksection (params) {
    return Service.get(
      `/${ServiceName}/api/external/workPlan/queryactivitysections`
    )
  },
  // 查询分票
  getDivideVotes (params) {
    return Service.get(
      `/${ServiceName}/api/external/publics/getDivideVotesTwo`
    )
  },
  /**
   * 根据船名航次Id查询船舶交接量、贸别、货物名称
   */
  getDataById (shipvoyageId) {
    return Service.get(
      `/${ServiceName}/api/external/TBusOrderController/queryShipId?shipvoyageId=${shipvoyageId}`
    )
  },
  /**
   * 查询外理单位
   */
   queryCustomer () {
    return Service.get(
      `/${ServiceName}/api/external/DispatchWorkerController/queryCustomer`
    )
  },
  /**
   * 获取当前时间班次
   */
   getScheduleNow () {
    return Service.get(
      `/${ServiceName}/api/external/publics/getScheduleNow`
    )
  },
}

export default publicapi
